/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package xxub.oracle.apps.xxierp.travel.webui;

import com.sun.java.util.collections.HashMap;

import java.io.Serializable;

import java.text.SimpleDateFormat;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAHeaderBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAMessageComponentLayoutBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageCheckBoxBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

import oracle.apps.fnd.framework.webui.beans.nav.OAPageButtonBarBean;

import oracle.cabo.style.CSSStyle;

import oracle.jbo.Row;
import oracle.jbo.ViewObject;
import oracle.jbo.domain.Date;


/**
 * Controller for ...
 */
public class RequestCO extends OAControllerImpl {
    public static final String RCS_ID = "$Header$";
    public static final boolean RCS_ID_RECORDED = 
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
    public String globalPrevDt;


    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
        super.processRequest(pageContext, webBean);
        OAApplicationModule am = pageContext.getApplicationModule(webBean);

        String loginUserSup = pageContext.getUserName();
        String respName = pageContext.getResponsibilityName();
        int respId = pageContext.getResponsibilityId();
        String superviser = "THSMITH";
        if (loginUserSup.equals(superviser) || 
            respName.equalsIgnoreCase("Manager Self-Service")) { //Approver Mode

            /* OAPageLayoutBean pageLayOutRN =
                 (OAPageLayoutBean)webBean.findChildRecursive("pageLayOutRN");
            pageLayOutRN.setWindowTitle("Approve");*/

            OASubmitButtonBean saveBtn = 
                (OASubmitButtonBean)webBean.findChildRecursive("Save");
            saveBtn.setRendered(false);
            OASubmitButtonBean submitBtn = 
                (OASubmitButtonBean)webBean.findChildRecursive("Submit");
            submitBtn.setRendered(false);

            Serializable[] loginUser = { pageContext.getUserName() };
            am.invokeMethod("queryLoginUser", loginUser);

            OAViewObject empVO = 
                (OAViewObject)am.findViewObject("EmployeeDtlsVO1");
            Row r[] = empVO.getAllRowsInRange();
            String appFullName = (String)r[0].getAttribute("ReqFullName");
            String appPersonId = 
                (String)r[0].getAttribute("PersonId").toString();
        } else {
            OASubmitButtonBean approveBtn = 
                (OASubmitButtonBean)webBean.findChildRecursive("Approve");
            approveBtn.setRendered(false);
            OASubmitButtonBean rejectBtn = 
                (OASubmitButtonBean)webBean.findChildRecursive("Reject");
            rejectBtn.setRendered(false);
        }

        String CStatus = "";
        CStatus = pageContext.getParameter("Status");
        System.out.println(CStatus);

        String l_HdrId = "";
        String l_Person_Id = "";
        String l_FullName = "";
        String l_Org = ""; //department
        String l_Dep_Id = "";

        CSSStyle promptfont = new CSSStyle();
        promptfont.setProperty("font-weight", "bold");

        l_Person_Id = pageContext.getParameter("pPersonId");
        l_FullName = pageContext.getParameter("pFullName");
        l_Org = pageContext.getParameter("pOrganization");
        l_Dep_Id = pageContext.getParameter("pDeptId");
        String seqNo = " ";

        if (!pageContext.getParameter("paramStatusId").equals("TC01")) {
            OAMessageDateFieldBean fromDt = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("FromDt");
            OAMessageDateFieldBean toDt = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("ToDt");
            OAMessageTextInputBean remarks = 
                (OAMessageTextInputBean)webBean.findChildRecursive("Remarks");
            OAMessageCheckBoxBean include = 
                (OAMessageCheckBoxBean)webBean.findChildRecursive("Include");
            fromDt.setReadOnly(true);
            toDt.setReadOnly(true);
            remarks.setDisabled(true);
            include.setReadOnly(true);
        }

        if (CStatus == "Create" || CStatus.equalsIgnoreCase("Create")) {
            if (!pageContext.isFormSubmission()) {
                Serializable[] initParams = { l_Person_Id };
                am.invokeMethod("CreateTrvlConcessionHdr");
                OAMessageTextInputBean trvlReqNumber = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("TravelConReqNo");
                OAMessageDateFieldBean trvlReqDate = 
                    (OAMessageDateFieldBean)webBean.findChildRecursive("TravelConReqDate");
                OAMessageTextInputBean empName = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("ReqesterName");
                OAMessageTextInputBean deptName = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("EmpDepName");
                OAMessageTextInputBean personId = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("PersonId");
                OAMessageTextInputBean empDeptId = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("EmpDeptNo");
                OAMessageTextInputBean status = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
                OAMessageTextInputBean statusDesc = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("StatusDesc");
                l_HdrId = trvlReqNumber.getText(pageContext);

                if (l_HdrId == null) {

                    OADBTransaction transaction = 
                        (OADBTransaction)am.getOADBTransaction();

                    Date cDate = transaction.getCurrentDBDate();
                    String strDT = cDate.toString().substring(0, 10);

                    Serializable[] stringDt = { strDT };
                    strDT = 
                            (String)am.invokeMethod("returnDateInString", stringDt);
                    java.sql.Date currDate = cDate.dateValue();
                    seqNo = 
                            transaction.getSequenceValue("XXIERP.TRVL_CONCESSION_REQ_NO").toString();
                    seqNo = String.format("%5s", seqNo);
                    seqNo = seqNo.replace(" ", "0");
                    trvlReqNumber.setValue(pageContext, seqNo);

                    ViewObject v01 = 
                        am.findViewObject("XxierpTravelConcessionVO1");
                    trvlReqDate.setValue(pageContext, currDate);
                    //     deptName.setValue(pageContext, l_Org);
                    //        empName.setValue(pageContext, l_FullName);
                    Serializable[] s2 = { strDT, l_Person_Id };
                    am.invokeMethod("queryEmployeeHisRecordVO", s2);
                    personId.setValue(pageContext, l_Person_Id);
                    empDeptId.setValue(pageContext, l_Dep_Id);
                    status.setValue(pageContext, "TC01");
                    OAViewObject statusVO = 
                        (OAViewObject)am.findViewObject("TravelConStatusVO1");
                    statusVO.setWhereClauseParams(null);
                    statusVO.setWhereClause("LOOKUP_CODE='TC01'");
                    statusVO.executeQuery();
                    personId.setRendered(false);
                }
            }
            /**+++++++ "For Create" START of Previous Transaction Details  +++++++*/
            String previousTranscDate;
            previousTranscDate = 
                    pageContext.getParameter("PreviousTranscDate").toString();
            globalPrevDt = previousTranscDate;
            Serializable[] strDt = { previousTranscDate };
            previousTranscDate = 
                    (String)am.invokeMethod("returnDateInString", strDt);
            OAViewObject hisVo;
            hisVo = 
                    (OAViewObject)am.findViewObject("XxierpTravelConcessionHistoryVO1");
            hisVo.setWhereClause(null);
            hisVo.setWhereClause("PERSON_ID='" + l_Person_Id + "'" + 
                                 " AND TRAVEL_CON_REQ_DATE= '" + 
                                 previousTranscDate + "'");
            hisVo.executeQuery();

            /*    OAMessageTextInputBean RefNumber =
                (OAMessageTextInputBean)webBean.findChildRecursive("RefNo");
            OAMessageDateFieldBean trvlPrevDate =
                (OAMessageDateFieldBean)webBean.findChildRecursive("Date");
            OAMessageTextInputBean concessionAmt =
                (OAMessageTextInputBean)webBean.findChildRecursive("ConcessionAmt");*/

            /**+++++++ "For Create" END of Previous Transaction Details  +++++++*/


            /**+++++++ "For Create" START of Populating Data for  Detail Records +++++++*/

            OAViewObject relationsVO = 
                (OAViewObject)am.findViewObject("RelationshipsVO1");
            relationsVO.setWhereClause("PERSON_ID = " + l_Person_Id);
            relationsVO.executeQuery();
            oracle.jbo.ViewObject dtlRow = 
                (ViewObject)am.findViewObject("xxierpTravelLeaveDtlVO1");
            Serializable[] ser = { seqNo };
            am.invokeMethod("queryTravelConcessionDtls", ser);
            dtlRow.executeQuery();
            OAMessageTextInputBean Reqno = 
                (OAMessageTextInputBean)webBean.findChildRecursive("TravelConReqNo1");
            OAMessageTextInputBean fuNameDis = 
                (OAMessageTextInputBean)webBean.findChildRecursive("FullName");
            OAMessageTextInputBean relationDesc = 
                (OAMessageTextInputBean)webBean.findChildRecursive("RelationshipDesc");
            Row row;
            int lineNumber = 1;
            double total = 0;
            while ((row = relationsVO.next()) != null) {
                String depenName = (String)row.getAttribute("FullName");
                String relationName = (String)row.getAttribute("Relationship");
                Row newRow = dtlRow.createRow();
                dtlRow.insertRow(newRow);
                Reqno.setValue(pageContext, seqNo);
                fuNameDis.setValue(pageContext, depenName);
                relationDesc.setValue(pageContext, relationName);
                newRow.setAttribute("DepnPersonId", 
                                    row.getAttribute("Dpnperid"));
                newRow.setAttribute("DepnRelation", 
                                    row.getAttribute("RelationshipId"));
                newRow.setAttribute("DepnAge", 0);
                newRow.setAttribute("Amount", 100.89);
                newRow.setAttribute("LineNum", lineNumber);
                lineNumber++;
                total = 
                        total + Double.parseDouble(newRow.getAttribute("Amount").toString());
            }
            /**+++++++ "For Create" END of Populating Data for  Detail Records +++++++*/

            OAMessageTextInputBean advanceAmount = 
                (OAMessageTextInputBean)webBean.findChildRecursive("AdvanceAmount");
            advanceAmount.setValue(pageContext, total);

        } else if (CStatus == "View" || CStatus.equalsIgnoreCase("View")) {
            seqNo = pageContext.getParameter("paramTrvlConReqNo");
            OAViewObject concsnHdr = 
                (OAViewObject)am.findViewObject("XxierpTravelConcessionVO1");
            concsnHdr.setWhereClause(null);
            concsnHdr.setWhereClause("TRAVEL_CON_REQ_NO= '" + seqNo + "'");
            concsnHdr.executeQuery();
            Row hdrRow = concsnHdr.first();
            String person = hdrRow.getAttribute("PersonId").toString();
            String statusId = hdrRow.getAttribute("StatusId").toString();
            OAViewObject statusVO = 
                (OAViewObject)am.findViewObject("TravelConStatusVO1");
            statusVO.setWhereClauseParams(null);
            statusVO.setWhereClause("LOOKUP_CODE='" + statusId + "'");
            statusVO.executeQuery();
            Serializable[] s2 = 
            { pageContext.getParameter("paramTrvlConReqDate"), person };
            am.invokeMethod("queryEmployeeHisRecordVO", s2);
            OAMessageTextInputBean trvlReqNumber = 
                (OAMessageTextInputBean)webBean.findChildRecursive("TravelConReqNo");
            OAMessageDateFieldBean trvlReqDate = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("TravelConReqDate");
            OAMessageTextInputBean empName = 
                (OAMessageTextInputBean)webBean.findChildRecursive("ReqesterName");
            OAMessageTextInputBean deptName = 
                (OAMessageTextInputBean)webBean.findChildRecursive("EmpDepName");
            OAMessageTextInputBean statusDesc = 
                (OAMessageTextInputBean)webBean.findChildRecursive("StatusDesc");

            /**+++++++ "For View" START of Previous Transaction Details  +++++++*/
            if (loginUserSup.equals(superviser) || 
                respName.equalsIgnoreCase("Manager Self-Service")) {

                String previousTranscDate;
                previousTranscDate = 
                        pageContext.getParameter("paramTrvlConReqDate").toString();
                OAViewObject hisVo;
                hisVo = 
                        (OAViewObject)am.findViewObject("XxierpTravelConcessionHistoryVO1");
                hisVo.setWhereClause(null);
                hisVo.setWhereClauseParams(null);
                l_Person_Id = pageContext.getParameter("paramPersonId");
                hisVo.setWhereClause("PERSON_ID='" + l_Person_Id + "'" + 
                                     " AND TRAVEL_CON_REQ_DATE < '" + 
                                     previousTranscDate + "'");
                hisVo.setOrderByClause("TRAVEL_CON_REQ_DATE DESC");
                hisVo.executeQuery();
                OAMessageTextInputBean RefNumber = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("RefNo");
                OAMessageDateFieldBean trvlPrevDate = 
                    (OAMessageDateFieldBean)webBean.findChildRecursive("Date");
                OAMessageTextInputBean concessionAmt = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("ConcessionAmt");
            } else {
                String previousTranscDate;
                previousTranscDate = 
                        pageContext.getParameter("paramTrvlConReqDate").toString();
                OAViewObject hisVo;
                hisVo = 
                        (OAViewObject)am.findViewObject("XxierpTravelConcessionHistoryVO1");
                hisVo.setWhereClause(null);
                hisVo.setWhereClauseParams(null);
                hisVo.setWhereClause("PERSON_ID='" + l_Person_Id + "'" + 
                                     " AND TRAVEL_CON_REQ_DATE < '" + 
                                     previousTranscDate + "'");
                hisVo.setOrderByClause("TRAVEL_CON_REQ_DATE DESC");
                hisVo.executeQuery();
                OAMessageTextInputBean RefNumber = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("RefNo");
                OAMessageDateFieldBean trvlPrevDate = 
                    (OAMessageDateFieldBean)webBean.findChildRecursive("Date");
                OAMessageTextInputBean concessionAmt = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("ConcessionAmt");

            }
            /**+++++++ "For View"   END of Previous Transaction Details  +++++++*/

            /**+++++++ "For View"  START of Populating Data for  Detail Records +++++++*/
            ViewObject vdtl = 
                (ViewObject)am.findViewObject("xxierpTravelLeaveDtlVO1");
            vdtl.setWhereClauseParams(null);
            vdtl.setWhereClause("TRAVEL_CON_REQ_NO= '" + seqNo + "'");
            vdtl.setOrderByClause("DEPN_PERSON_ID");
            vdtl.executeQuery();
            System.out.println(vdtl.getRowCount());
            Row row;
            String str = "";
            for (int i = 0; i < vdtl.getRowCount(); i++) {
                row = vdtl.next();
                if (i == 0)
                    str = str + row.getAttribute("DepnPersonId");
                else
                    str = str + "," + row.getAttribute("DepnPersonId");
                ViewObject voRelations = 
                    (ViewObject)am.findViewObject("RelationshipsVO1");
                voRelations.setWhereClause(null);
                voRelations.setWhereClause("RELATIONSHIP_ID= '" + 
                                           row.getAttribute("DepnRelation").toString() + 
                                           "'" + " AND DPNPERID= '" + 
                                           row.getAttribute("DepnPersonId").toString() + 
                                           "'");
                voRelations.executeQuery();
                Row relationRow = voRelations.first();
                row.setAttribute("RelationshipName", 
                                 relationRow.getAttribute("Relationship").toString());
            }
            ViewObject personVO = (ViewObject)am.findViewObject("PersonsVO1");
            personVO.setWhereClause("PERSON_ID IN(" + str + ")");
            personVO.setOrderByClause("PERSON_ID");
            personVO.executeQuery();
            Row depnRow;
            row = vdtl.first();
            while ((depnRow = personVO.next()) != null) {
                String fullName = 
                    depnRow.getAttribute("LastName") + " " + depnRow.getAttribute("FirstName");
                if (depnRow.getAttribute("Title") != null) {
                    fullName = depnRow.getAttribute("Title") + " " + fullName;
                }
                row.setAttribute("FullName", fullName);
                row = vdtl.next();
            }
            OAMessageTextInputBean fuNameDis = 
                (OAMessageTextInputBean)webBean.findChildRecursive("FullName");
            OAMessageTextInputBean relationDesc = 
                (OAMessageTextInputBean)webBean.findChildRecursive("RelationshipDesc");
            /**+++++++ "For View"  END of Populating Data for  Detail Records +++++++*/
        }

        /**+++++++ "For View"  START of Populating Data for  Approver Details +++++++*/

        if (loginUserSup.equals(superviser) || 
            respName.equalsIgnoreCase("Manager Self-Service")) {

            OAHeaderBean appHdrRG = 
                (OAHeaderBean)webBean.findChildRecursive("Hdr21");
            appHdrRG.setRendered(true);
            OAMessageComponentLayoutBean appDtlsRG = 
                (OAMessageComponentLayoutBean)webBean.findChildRecursive("ApproverDtls");
            appDtlsRG.setRendered(true);

            OADBTransaction transaction = 
                (OADBTransaction)am.getOADBTransaction();
            Date cDate = transaction.getCurrentDBDate();
            java.sql.Date currDate = cDate.dateValue();
            OAMessageDateFieldBean approvedDt = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("ApprovedDate");
            approvedDt.setValue(pageContext, currDate);
            OAViewObject empVO = 
                (OAViewObject)am.findViewObject("EmployeeDtlsVO1");
            empVO.setWhereClause(null);
            empVO.setWhereClause("USER_NAME='" + 
                                 pageContext.getUserName().toString() + "'");
            empVO.executeQuery();
            Row appRow = empVO.first();
            String appFullName = appRow.getAttribute("ReqFullName").toString();
            String appPersonId = appRow.getAttribute("PersonId").toString();
            OAMessageTextInputBean appName = 
                (OAMessageTextInputBean)webBean.findChildRecursive("ApproverName");
            OAMessageTextInputBean appPerID = 
                (OAMessageTextInputBean)webBean.findChildRecursive("ApproverId");
            appName.setValue(pageContext, appFullName);
            appPerID.setValue(pageContext, appPersonId);
            if (!pageContext.getParameter("paramStatusId").toString().equals("TC02")) {
                OAMessageTextInputBean appremarks = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("AppRemarks");
                appremarks.setDisabled(true);
                OASubmitButtonBean approveBtn = 
                    (OASubmitButtonBean)webBean.findChildRecursive("Approve");
                approveBtn.setDisabled(true);
                OASubmitButtonBean rejectBtn = 
                    (OASubmitButtonBean)webBean.findChildRecursive("Reject");
                rejectBtn.setDisabled(true);
            }
        }
        /**+++++++ "For View"  END of Populating Data for  Approver Details +++++++*/
    }


    /** Procedure to handle form submissions for form elements in
     * a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);

        OAApplicationModule am = pageContext.getApplicationModule(webBean);

        if ("Save".equals(pageContext.getParameter(EVENT_PARAM))) {
            OAMessageDateFieldBean tConReqDate = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("TravelConReqDate");
            OAMessageDateFieldBean fromDt = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("FromDt");
            OAMessageDateFieldBean toDt = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("ToDt");

            java.util.Date fromDate = null;
            java.util.Date reqDate = null;
            java.util.Date toDate = null;

            try {
                SimpleDateFormat dateFormat = 
                    new SimpleDateFormat("yyyy-MM-dd");
                fromDate = 
                        (java.util.Date)dateFormat.parse(fromDt.getValue(pageContext).toString());
                reqDate = 
                        (java.util.Date)dateFormat.parse(tConReqDate.getValue(pageContext).toString());
                toDate = 
                        (java.util.Date)dateFormat.parse(toDt.getValue(pageContext).toString());
            } catch (Exception e) {
                System.out.println("Exception in Date Convertion");
            }
            if (fromDate.before(reqDate)) {

                OAException validatedt = 
                    new OAException("From Date Should not be a less than Request Date !", 
                                    OAException.ERROR);
                pageContext.putDialogMessage(validatedt);
            } else if (toDate.before(fromDate)) {
                OAException validatedt = 
                    new OAException("To Date Should not be less than From Date !", 
                                    OAException.ERROR);
                pageContext.putDialogMessage(validatedt);
            } else {
                OAViewObject concsnHdr = 
                    (OAViewObject)am.findViewObject("XxierpTravelConcessionVO1");
                OAMessageTextInputBean pageStatusAtSave = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
                if (pageStatusAtSave.getValue(pageContext).equals("TC01")) {
                    am.invokeMethod("apply");
                    OAException successMessage = 
                        new OAException("Request has been Saved Successully.", 
                                        OAException.CONFIRMATION);
                    pageContext.putDialogMessage(successMessage);
                } else {
                    OAException successMessage = 
                        new OAException("You can Save the Request only when the Status is 'New'", 
                                        OAException.ERROR);
                    pageContext.putDialogMessage(successMessage);
                }
            }
        } else if ("Submit".equals(pageContext.getParameter(EVENT_PARAM))) {
            OAMessageTextInputBean reqNo = 
                (OAMessageTextInputBean)webBean.findChildRecursive("TravelConReqNo");
            OAMessageTextInputBean perNo = 
                (OAMessageTextInputBean)webBean.findChildRecursive("PersonId");
            OAMessageDateFieldBean reqDate = 
                (OAMessageDateFieldBean)webBean.findChildRecursive("TravelConReqDate");
            Serializable[] serNo = { reqNo.getValue(pageContext).toString() };
            String reqNoExists;
            reqNoExists = (String)am.invokeMethod("requestNoExists", serNo);
            if (reqNoExists.equals("N")) {
                String previousTranscDate;
                previousTranscDate = globalPrevDt;
                Serializable[] strDt = { previousTranscDate };
                previousTranscDate = 
                        (String)am.invokeMethod("returnDateInString", strDt);
                OAViewObject hisVo;
                hisVo = 
                        (OAViewObject)am.findViewObject("XxierpTravelConcessionHistoryVO1");
                hisVo.setWhereClause(null);
                String a;
                a = perNo.getValue(pageContext).toString();
                hisVo.setWhereClause("PERSON_ID='" + 
                                     perNo.getValue(pageContext).toString() + 
                                     "'" + " AND TRAVEL_CON_REQ_DATE= '" + 
                                     previousTranscDate + "'");
                hisVo.executeQuery();
                OAException successMessage = 
                    new OAException("Request must be Saved before Submit !", 
                                    OAException.ERROR);
                pageContext.putDialogMessage(successMessage);
            } else {

                OAViewObject concsnHdr = 
                    (OAViewObject)am.findViewObject("XxierpTravelConcessionVO1");
                Row[] pageHdrRow = concsnHdr.getAllRowsInRange();
                OAMessageTextInputBean pageStatusIdBeforeSubmit = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
                String pageStatusIdAtSubmit;
                pageStatusIdAtSubmit = 
                        pageStatusIdBeforeSubmit.getValue(pageContext).toString();
                OAViewObject statusVO = 
                    (OAViewObject)am.findViewObject("TravelConStatusVO1");
                statusVO.setWhereClauseParams(null);
                statusVO.setWhereClause("LOOKUP_CODE='" + "TC02" + "'");
                statusVO.executeQuery();
                HashMap hm = new HashMap();
                hm.put("paramStatusId", "TC02");
                hm.put("paramTrvlConReqNo", 
                       reqNo.getValue(pageContext).toString());
                String strDT = reqDate.getValue(pageContext).toString();
                Serializable[] strDt2 = { strDT };
                strDT = (String)am.invokeMethod("returnDateInString", strDt2);
                hm.put("paramTrvlConReqDate", strDT);
                hm.put("Status", "View");
                if (pageStatusIdAtSubmit.equals("TC01")) {
                    //pageHdrRow[0].setAttribute("StatusId", "TC02");
                    concsnHdr.getCurrentRow().setAttribute("StatusId", "TC02");
                    am.invokeMethod("apply");
                    OAException successMessage = 
                        new OAException("Request has been Submitted!", 
                                        OAException.CONFIRMATION);
                    pageContext.putDialogMessage(successMessage);
                } else {
                    OAException successMessage = 
                        new OAException("You can Submit the Request only when the Status is 'New'", 
                                        OAException.ERROR);
                    pageContext.putDialogMessage(successMessage);
                }
                pageContext.forwardImmediatelyToCurrentPage(hm, true, 
                                                            "OA.jsp?page=/xxub/oracle/apps/xxierp/travel/webui/RequestPG");

            }
        } else if ("Cancel".equals(pageContext.getParameter(EVENT_PARAM))) {
            am.invokeMethod("rollbackRecords");
            pageContext.forwardImmediately("OA.jsp?page=/xxub/oracle/apps/xxierp/travel/webui/xxierptrvlconsessionPG", 
                                           null, 
                                           OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                           null, null, false, 
                                           OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
        } else if ("Approve".equals(pageContext.getParameter(EVENT_PARAM))) {

            OAViewObject concesionVO = 
                (OAViewObject)am.findViewObject("XxierpTravelConcessionVO1");
            concesionVO.getCurrentRow().setAttribute("StatusId", "TC03");
            am.invokeMethod("apply");
            OAException successMessage = 
                new OAException("Request has been Approved Successfully!", 
                                OAException.CONFIRMATION);
            pageContext.putDialogMessage(successMessage);

            pageContext.forwardImmediately("OA.jsp?page=/xxub/oracle/apps/xxierp/travel/webui/xxierptrvlconsessionPG", 
                                           null, 
                                           OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                           null, null, true, 
                                           OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
        } else if ("Reject".equals(pageContext.getParameter(EVENT_PARAM))) {

            OAViewObject concesionVO = 
                (OAViewObject)am.findViewObject("XxierpTravelConcessionVO1");
            concesionVO.getCurrentRow().setAttribute("StatusId", "TC04");
            am.invokeMethod("apply");

            OAException successMessage = 
                new OAException("Request has been Rejected!", 
                                OAException.CONFIRMATION);
            pageContext.putDialogMessage(successMessage);
            pageContext.forwardImmediately("OA.jsp?page=/xxub/oracle/apps/xxierp/travel/webui/xxierptrvlconsessionPG", 
                                           null, 
                                           OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                           null, null, true, 
                                           OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
        }
    }
}


//*************************** /*Rajnish Code**********************************************//
/* am.invokeMethod("CreateNewVO");
      OAViewObject trvlConcession = (OAViewObject)am.findViewObject("LastTravlConcessionDateVO");
      Row r[]=trvlConcession.getAllRowsInRange();
      String no=  (String)r[0].getAttribute(0);
      String no1=  (String)r[0].getAttribute(1);
      String no2=  (String)r[0].getAttribute(2);
      System.out.println(no);
      System.out.println(no1);
      System.out.println(no2);*/
//*************************** /*Rajnish Code Ends**********************************************//
